home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / buildwp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  2.6 KB  |  119 lines

  1. #include <stdio.h>
  2. #include <dir.h>
  3. #include <dos.h>
  4. #include <time.h>
  5. #include <fcntl.h>
  6. #include <sys\stat.h>
  7.  
  8. char *WhitePages = "spool/wpagebbs";
  9. #define NULLFILE (FILE *) 0
  10. #define NULLCHAR (char *) 0
  11. #define LINELEN 128
  12. #define    READ_TEXT    "rt"
  13. #define    APPEND_TEXT    "at+"
  14.  
  15. void
  16. wpageUpdate(fp, string, entry, oldtime)
  17. FILE *fp;
  18. char *string, *entry, *oldtime;
  19. {
  20. time_t now;
  21.  
  22.     time(&now);
  23.     fprintf(fp,"%-32s %-14ld\n",entry,now); // update time stamp
  24. }
  25.  
  26.  
  27. // Returns a copy (strdup'ed) of existing entry if string is in whitepages file
  28. char *
  29. wpageCheck(string)
  30. char *string;
  31. {
  32. char buf[LINELEN], *cp, *retval = NULLCHAR;
  33. FILE *fp;
  34.  
  35.     if (string && ((fp = fopen(WhitePages,"r+t")) != NULLFILE))    {
  36.         while(fgets(buf, LINELEN, fp) != NULLCHAR)    {
  37.             /* Get rid of following spaces or tabs, to separate the
  38.              * h_addr and it's time stamp entry
  39.              */
  40.             if( ((cp=strchr(buf,' ')) != NULLCHAR) || \
  41.                 ((cp=strchr(buf,'\t')) != NULLCHAR) )
  42.                     *cp = '\0';
  43.             if(!strnicmp(string,buf, strlen(string)))    {
  44.                 retval = strdup (buf);
  45.                 fseek (fp, (long) -49, SEEK_CUR);
  46.                 wpageUpdate (fp, string, buf, &buf[33]);
  47.                 break;
  48.             }
  49.         }
  50.         fclose(fp);
  51.     }
  52.     return retval;
  53. }
  54.      
  55.  
  56. void
  57. wpageAdd (entry)
  58. char *entry;
  59. {
  60. time_t now;
  61. FILE *fp;
  62. char *last;
  63.  
  64.     if (entry == NULLCHAR)
  65.         return;
  66.     last = wpageCheck (entry);
  67.     free (last);
  68.     if (!last)    {
  69.         time(&now);
  70.         if((fp = fopen(WhitePages,APPEND_TEXT)) != NULLFILE) {
  71.             fprintf(fp,"%s %-14ld\n",entry,now); /* Save h_addr in whitepages file */
  72.             fclose(fp);
  73.         }
  74.     }
  75.  
  76. }
  77.  
  78.  
  79. main ()
  80. {
  81. FILE *tmpfile;
  82. struct ffblk ff;
  83. char buf[LINELEN], *cp, *cp2;
  84. char fname[32];
  85.  
  86.     strcpy(buf,"spool/mail/*.txt");
  87.     if (findfirst(buf, &ff, 0) == 0) {
  88.         do    {
  89.             sprintf (fname, "spool/mail/%s", ff.ff_name);
  90.             if ((tmpfile = fopen (fname,READ_TEXT)) != NULLFILE)    {
  91.                 while(fgets(buf,LINELEN,tmpfile) != NULLCHAR)    {
  92.                     if(!strnicmp(buf,"R:",2)) { /*found one*/
  93.                         /* Find the '@[:]CALL.STATE.COUNTRY'or
  94.                          * or the '?[:]CALL.STATE.COUNTRY' string
  95.                          * The : is optional.
  96.                          */
  97.                         if( ((cp=strchr(buf,'@')) != NULLCHAR) ||
  98.                             ((cp=strchr(buf,'?')) != NULLCHAR) ) {
  99.                                 if((cp2=strchr(cp,' ')) != NULLCHAR)
  100.                                     *cp2 = '\0';
  101.                                 if((cp2=strchr(cp,'\n')) != NULLCHAR)
  102.                                     *cp2 = '\0';
  103.                                 if((cp2=strchr(cp,'\t')) != NULLCHAR)
  104.                                     *cp2 = '\0';
  105.                                 /* Some bbs's send @bbs instead of @:bbs*/
  106.                                 if (*++cp == ':')
  107.                                     cp++;
  108.                                     wpageAdd (cp);
  109.                                     printf("%s: Adding '%s'\n", ff.ff_name, cp);
  110.                             }
  111.                     }
  112.                 }
  113.                 fclose (tmpfile);
  114.             }
  115.  
  116.         } while (findnext(&ff) == 0);
  117.     }
  118. }
  119.